import 'package:douban/pages/group/grop.dart';
import 'package:douban/pages/home/home.dart';
import 'package:douban/pages/main/main.dart';
import 'package:douban/pages/mall/mall.dart';
import 'package:douban/pages/profile/profile.dart';
import 'package:douban/pages/subject/subject.dart';
import 'package:flutter/material.dart';

void main() {
  runApp(const MyApp());
}

class MyApp extends StatelessWidget {
  const MyApp({Key? key}) : super(key: key);

  // This widget is the root of your application.
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Flutter Demo',
      theme: ThemeData(
          primarySwatch: Colors.green, splashColor: Colors.transparent),
      home: MyHomePage(),
    );
  }
}

class MyHomePage extends StatefulWidget {
  @override
  State<MyHomePage> createState() => _MyHomePageState();
}

class _MyHomePageState extends State<MyHomePage> {
  int flag = 0;
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text("test"),
        backgroundColor: Colors.greenAccent,
      ),
      body: IndexedStack(
        index: flag,
        children: [
          mainpage(),
          subjectpage(),
          profile(),
          mallpage(),
          homespage(),
          groupage()
        ],
      ),
      bottomNavigationBar: BottomNavigationBar(
        currentIndex: flag,
        type: BottomNavigationBarType.fixed,
        items:bottombar(),
        onTap: ((index){
          setState(() {
            flag =index;
          });
        }),
      )
    );
  }
}

//抽取地步导航的使用
class Bottombaritem extends BottomNavigationBarItem {
  Bottombaritem(String iconName, String title)
      : super(
          title: Text(title),
          icon: Icon(Icons.home),
          activeIcon: Icon(Icons.account_tree_rounded),
        );
}

List<BottomNavigationBarItem> bottombar() {
  return const [
      BottomNavigationBarItem(
        title: Text("首页"),
        icon: Icon(Icons.home),
        backgroundColor: Colors.greenAccent,
      ),
      BottomNavigationBarItem(
          title: Text("书影音"),
          icon: Icon(Icons.book),
          backgroundColor: Colors.redAccent),
      BottomNavigationBarItem(
          title: Text("小组"), icon: Icon(Icons.games_outlined)),
      BottomNavigationBarItem(
          title: Text("市场"), icon: Icon(Icons.subscriptions)),
      BottomNavigationBarItem(
          title: Text("个人中心"), icon: Icon(Icons.perm_contact_calendar)),
    ];

}
